import torch
import matplotlib.pyplot as plt


def sigmoid(x):
    return 1 / (1 + torch.exp(-x))


def tanh(x):
    return (torch.exp(x) - torch.exp(-x)) / (torch.exp(x) + torch.exp(-x))


x = torch.linspace(-6, 6, 50)
ax1 = plt.subplot(121)
ax1.plot(x.detach().numpy(), sigmoid(x).detach().numpy(), 'r-')
ax2 = plt.subplot(122)
ax2.plot(x.detach().numpy(), tanh(x).detach().numpy(), 'r-')
plt.show()
